home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / GameViewport.as < prev    next >
Text File  |  2006-11-29  |  2KB  |  71 lines

  1. class GameViewport extends SSViewport
  2. {
  3.    var stallTime = 0;
  4.    var lockPos = false;
  5.    var response = 1.7;
  6.    var xLead = 0.4;
  7.    var shake = 0;
  8.    var strength = 2;
  9.    var lastShake = 0;
  10.    var locked = false;
  11.    function GameViewport()
  12.    {
  13.       super();
  14.    }
  15.    function stall(time)
  16.    {
  17.       this.stallTime = time;
  18.    }
  19.    function shakeCamera(time, amount)
  20.    {
  21.       this.shake = time;
  22.       this.strength = amount;
  23.       this.lastShake = 0;
  24.    }
  25.    function lock()
  26.    {
  27.       this.locked = true;
  28.    }
  29.    function unlock()
  30.    {
  31.       this.locked = false;
  32.    }
  33.    function update(elapsed)
  34.    {
  35.       if(!this.watch)
  36.       {
  37.          return undefined;
  38.       }
  39.       if(this.stallTime)
  40.       {
  41.          this.stallTime = Math.max(0,this.stallTime - elapsed);
  42.       }
  43.       else if(this.watch.finished)
  44.       {
  45.          this.moveTo(Math.round(this.x + (this.watch.x - this.x) * elapsed * 4),Math.round(this.y + (this.watch.y - this.y - 100) * elapsed * 4),this.focusDepth);
  46.       }
  47.       else if(!this.locked)
  48.       {
  49.          if(this.watch.swinging)
  50.          {
  51.             var _loc3_ = 0;
  52.             this.tx = this.watch.x + (this.watch.dispAxis * this.halfWidth * this.xLead + this.watch.velocity.x) / 4;
  53.             this.ty = this.watch.y + (_loc3_ + this.watch.velocity.y) / 4;
  54.          }
  55.          else
  56.          {
  57.             _loc3_ = !(this.watch.jumpTime || !this.watch.inMotion) ? Math.min(Math.max(this.watch.velocity.y * 0.5,-150),150) : this.watch.contactNormal.y * this.halfHeight * 0.2 + this.watch.dispAxis * this.watch.contactNormal.x * this.halfHeight * 0.7;
  58.             this.tx = this.watch.x + (this.watch.dispAxis * this.halfWidth * this.xLead + this.watch.velocity.x) / this.response;
  59.             this.ty = this.watch.y + (_loc3_ + this.watch.velocity.y) / this.response;
  60.          }
  61.          this.moveTo(Math.round((this.x + (this.tx - this.x) * elapsed * this.response) * 4) / 4,Math.round((this.y + (this.ty - this.y) * elapsed * this.response) * 4) / 4,this.focusDepth);
  62.       }
  63.       if(this.shake)
  64.       {
  65.          this.shake = Math.max(0,this.shake - elapsed);
  66.          this.lastShake += 1;
  67.          this.moveBy(0,(this.lastShake % 2 != 1 ? 1 : -1) * this.strength,0);
  68.       }
  69.    }
  70. }
  71.